﻿namespace EasyCMS.Common.Querys
{
    using System;
    using Pismire;


    [System.Runtime.Serialization.DataContractAttribute(Name = "Category", Namespace = "http://schemas.datacontract.org/2004/07/EasyCMS.Common.Querys")]
    public class Category : Pismire.Querys.QueryBase
    {
        #region key
        /// <summary>
        /// 缓存键
        /// </summary>
        public override string Key
        {
            get { return string.Format(KeyFormat, ParentID, Type, PartitionMark, DisplayName, TemplateName); }
        }
        private const string KeyFormat = "Admin_ParentID{0}Type{1}PartitionMark{2}DisplayName{3}TemplateName{4}";
        #endregion

        #region ParentID
        /// <summary>
        /// ParentID
        /// </summary>
        public int ParentID
        {
            get { return m_ParentID; }
            set
            {
                m_ParentID = value;
                this.HasParentID = (value > -1) ? true : false;
            }
        }
        private int m_ParentID;
        public bool HasParentID { get; private set; }
        public static ExcuteState ParentID_Validate(ref int parentID)
        {
            return parentID.Validation("ParentID").MoreThan(-1).State;
        }
        #endregion

        #region Type
        /// <summary>
        /// Type
        /// </summary>
        public Enums.CategoryType Type
        {
            get { return m_Type; }
            set
            {
                m_Type = value;
                if (value.Validation("CategoryType").NotDefault().State.Succeed) HasType = true;
            }
        }
        private Enums.CategoryType m_Type;
        public bool HasType { get; private set; }
        #endregion

        #region PartitionMark
        /// <summary>
        /// PartitionMark
        /// </summary>
        public string PartitionMark
        {
            get { return m_PartitionMark; }
            set
            {
                m_PartitionMark = value;
                this.HasPartitionMark = (!String.IsNullOrEmpty(value)) ? true : false;
            }
        }
        private string m_PartitionMark;
        public bool HasPartitionMark { get; private set; }
        public static ExcuteState PartitionMark_Validate(ref string partitionMark)
        {
            return partitionMark.Validation("PartitionMark").LengthBetween(0, 20).Text(ValidationMode.Only).BindValue(ref partitionMark).State;
        }
        #endregion

        #region DisplayName
        /// <summary>
        /// DisplayName
        /// </summary>
        public string DisplayName
        {
            get { return m_DisplayName; }
            set
            {
                m_DisplayName = value;
                this.HasDisplayName = (!String.IsNullOrEmpty(value)) ? true : false;
            }
        }
        private string m_DisplayName;
        public bool HasDisplayName { get; private set; }
        public bool DisplayNameIsLike { get; set; }
        public static ExcuteState DisplayName_Validate(ref string displayName)
        {
            return displayName.Validation("DisplayName").LengthBetween(0, 20).Text(ValidationMode.Only).BindValue(ref displayName).State;
        }
        #endregion

        #region TemplateName
        /// <summary>
        /// TemplateName
        /// </summary>
        public string TemplateName
        {
            get { return m_TemplateName; }
            set
            {
                m_TemplateName = value;
                this.HasTemplateName = (!String.IsNullOrEmpty(value)) ? true : false;
            }
        }
        private string m_TemplateName;
        public bool HasTemplateName { get; private set; }
        public bool TemplateNameIsLike { get; set; }
        public static ExcuteState TemplateName_Validate(ref string templateName)
        {
            return templateName.Validation("TemplateName").LengthBetween(0, 20).Text(ValidationMode.Only).BindValue(ref templateName).State;
        }
        #endregion

        #region checkMe
        /// <summary>
        /// 检查合法性
        /// </summary>
        /// <returns></returns>
        public override ExcuteState CheckMe()
        {
            //初始化
            ExcuteState state = null;

            state = ParentID_Validate(ref this.m_ParentID);
            if (!state.Succeed) return state;

            state = PartitionMark_Validate(ref this.m_PartitionMark);
            if (!state.Succeed) return state;

            state = DisplayName_Validate(ref this.m_DisplayName);
            if (!state.Succeed) return state;

            state = TemplateName_Validate(ref this.m_TemplateName);
            if (!state.Succeed) return state;

            //返回
            return state;
        }
        #endregion
    }
}
